package com.atguigu.add;

import java.util.concurrent.CountDownLatch;

/**
 * @author sx
 * @date 2022-02-19 15:27
 */
public class CountDownLatchTest {
    public static void main(String[] args) throws InterruptedException {
        //总数为6，必须执行任务时使用
        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + " go out!");
                //数量减一
                countDownLatch.countDown();
            }, String.valueOf(i)).start();
        }

        //等待计数器归零，再往下执行
        countDownLatch.await();
        System.out.println("Close door!");
    }
}
